﻿<template>
    <div>
        <el-form label-width="150px" :model="Adduser" ref="Adduser_refs" :rules="rules" >
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="角色" prop="RoleId">
                        <el-select v-model="RoleIds" required multiple class="wmax">
                            <el-option v-for="(v,k) in AllRoleDB" :value="v.Id" :data-userid="v.Id" :label="v.RoleName" v-text="v.RoleName" />
                        </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工姓名" prop="UserName">
                        <el-input v-model="Adduser.UserName"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工性别" prop="Sex">
                        <el-radio v-model="Adduser.Sex" label="0">男</el-radio>
                        <el-radio v-model="Adduser.Sex" label="1">女</el-radio>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="身份证号码" prop="Card">
                        <el-input v-model="Adduser.Card"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工电话" prop="Phone">
                        <el-input v-model="Adduser.Phone"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="身份证地址" prop="FamilyAddress">
                        <el-input v-model="Adduser.FamilyAddress"></el-input>
                    </el-form-item>
                </el-col>

            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="员工工种" prop="JobNumber">
                        <el-input v-model="Adduser.JobNumber"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="初始密码" prop="Password">
                        <el-input v-model="Adduser.Password"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="卡开户行" prop="BankName">
                        <el-input v-model="Adduser.BankName"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="银行卡号码" prop="BankCardNumber">
                        <el-input v-model="Adduser.BankCardNumber"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
<!--            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="卡2开户行" prop="BankName2">
                        <el-input v-model="Adduser.BankName2"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="银行卡2号码" prop="BankCardNumber2">
                        <el-input v-model="Adduser.BankCardNumber2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row> -->
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="备注" prop="Remark">
                        <el-input v-model="Adduser.Remark"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="现居地" prop="NowFamilyAddress">
                        <el-input v-model="Adduser.NowFamilyAddress"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <el-form-item label="入职时间" prop="InductionTime">
                        <el-date-picker style="width: 100%"   v-model="Adduser.InductionTime"
                                        class="wmax"
                                        type="date"
                                        placeholder="选择日期">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <el-form-item label="工号" prop="UserNumber">
                        <el-input v-model="Adduser.UserNumber"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="10" :offset="1">
                    <h2>身份证</h2>
                    <el-form-item label="身份证"  prop="PostLevel">
                        <UploadFileF ref="AnotherData"
                                     :multiple="true"
                                     :another-data="AnotherData"
                                     :showfilelist="true"
                                     :upshow="false"
                                     content="点击上传身份证"
                                     btnsize="medium"></UploadFileF>
                    </el-form-item>
                </el-col>
                <el-col :span="10" :offset="1">
                    <h2>银行卡</h2>
                    <el-form-item label="银行卡"  prop="PostLevel">
                        <UploadFileF ref="AnotherData2"
                                     :multiple="true"
                                     :another-data="AnotherData2"
                                     :showfilelist="true"
                                     :upshow="false"
                                     content="点击上传银行卡"
                                     btnsize="medium"></UploadFileF>
                    </el-form-item>
					
<!-- 					<el-form-item label="银行卡2"  prop="PostLevel">
					    <UploadFileF ref="AnotherData3"
					                 :multiple="false"
					                 :another-data="AnotherData3"
					                 :showfilelist="true"
					                 :upshow="false"
					                 content="点击上传银行卡"
					                 btnsize="medium"></UploadFileF>
					</el-form-item> -->
                </el-col>
            </el-row>
            <el-row>
                <el-col align="center">
                    <el-button type="success" @click="AddUserSave">添加员工</el-button>
                    <el-button type="success" @click="AddUserreset">重置</el-button>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>
<script>
    import * as publicjs from "/public/Scriput/Public"
    import UploadFileF from "../UploadFileF";
    export default {
        props: {
            AllRoleDB: {
                type: Array,
                required: true
            },
        },
        components: {
            UploadFileF,
        },
        name: "AddUser",
        data() {
            return {
                rules: {
                    UserName: [
                        { required: true, message: '请输入用户名称', trigger: 'blur' },
                    ],
                    Phone: [
                         { required: true, message: '请输入电话号码', trigger: 'blur' },
                         { min: 11, max: 11, message: '请输入正确的电话号码', trigger: 'blur' }
                    ],
                    
                },
                RoleIds: [],
                UserPositions:[],
                Adduser: {
                    RoleId:'',
                    UserName: '',
                    Sex: '0',
                    Card: '',
                    InternshipState: '1',
                    Phone: '',
                    FamilyAddress: '',
                    UserPosition: '',
                    JobNumber: '',
                    Number: '',
                    Password: '111111',
                    InductionTime: new Date(),
                    BankName: '',
                    BankCardNumber: '',
                    Remark: '',
                    NowFamilyAddress: '',
                },
                //文件上传参数
                AnotherData: {
                    FileType: 1,
                    id: 0,
                    Type: 1,
                    Single: false,
                },
                AnotherData2: {
                    FileType: 1,
                    id: 0,
                    Type: 2,
                    Single: false,
                },
				AnotherData3: {
				    FileType: 1,
				    id: 0,
				    Type: 3,
				    Single: false,
				},
            }
        },
        created() {

        },
        methods: {
            AddUserSave() {
                this.$refs.Adduser_refs.validate((x, d) => {
                    if (x) {
                        this.Adduser.RoleId = this.RoleIds.join(',');
                        // this.Adduser.UserPosition = this.UserPositions.join(',');
                        let loadding = this.openLoading();
                        this.$http.post("UserInfo/AddUsersContent", { users: this.Adduser })
                            .then(res => {
                                loadding.close();
                                if (res.data.flag) {
                                    if (this.$refs['AnotherData'].fileList.length > 0) {
                                        this.AnotherData.id = res.data.id
                                        this.$refs['AnotherData'].submitUpload()
                                    }
                                    if (this.$refs['AnotherData2'].fileList.length > 0) {
                                        this.AnotherData2.id = res.data.id
                                        this.$refs['AnotherData2'].submitUpload()
                                    }
									// if (this.$refs['AnotherData3'].fileList.length > 0) {
									//     this.AnotherData3.id = res.data.id
									//     this.$refs['AnotherData3'].submitUpload()
									// }
                                    this.$parent.$parent.AddUserShow = false;
                                    this.$parent.$parent.GettableDB();
                                } else if (!res.data.bit) {
                                    this.$message.error("该账号,电话已存在,请重新输入");
                                } else {
                                    this.$message.error("数据获取失败");
                                }
                            }).catch(res => {
                                console.log(res);
                                loadding.close();
                            });
                    }
                });

            },
            AddUserreset() {
                this.$refs["Adduser_refs"].resetFields();
            },
        },
        mounted: function () {

        },
    }
</script>
<style scoped>
    .wmax {
        width: 100%;
    }
</style>
